<?php

namespace App\Providers;

use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
        Validator::extend('mobile',  function ($attribute, $value, $parameters, $validator) {
            $result = preg_match('/^(\\+?0?86-?)?1[1-9]\d{9}$/', $value);
            if(!$result) {
                $validator->errors()->add($attribute, 'The :attribute must be a mobile number.');
            }
            return $result;
        });
    }
}
